//
//  AppDelegate.m
//  NuwaRobot
//
//  Created by Kendama on 2017/11/29.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "AppDelegate.h"
#import "TabBarViewController.h"
#import "CoreJPush.h"
#import "DTCSharePlatformManager.h"
//#import "NSString+FIDExtra.h"
#import "InfraredApi.h"
#import "DataManager.h"
#import "AppDelegate+EaseMob.h"
#import "DTCLocalPushManager.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

+ (AppDelegate *)defaultService
{
    return (AppDelegate *)[[UIApplication sharedApplication]delegate];
}



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [self setNetworkBaseConfig];
    [self setBuglyConfig];
    // 喜马拉雅
    [self setXimalaya];
    // 讯飞语音
    [self setIFlyMSC];
    // 极光
    [CoreJPush registerJPush:launchOptions];
    // 环信初始化
    [self registerHuanXin:application];
    [self setHyphenate];
    [[DTCLocalPushManager defalutService]startLaunchOptions:launchOptions];
//    NSString *appkey = @"1149171121115130#nuwarobot";
//    [self easemobApplication:application didFinishLaunchingWithOptions:launchOptions appkey:appkey apnsCertName:ApnsCertName otherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];
    
    [DTCSharePlatformManager setShareConfig];
    
//    [[DTCLocalPushManager defalutService] removeAllLocalNotification];

    [self setRootViewController];
    [DataManager sharedInstance];
    
//    SAVE_OBJECT(@"1", DEVICEID);
    
    SAVE_OBJECT(@"13715881550", InfraredDeviceID);

    
//    InfraredApi *api = [[InfraredApi alloc] initWithDic:@{@"appid":EXRACT_OBJECT(InfraredAppId),@"c":@"t",@"f":EXRACT_OBJECT(InfraredDeviceID),@"m":@"none"}];
//    [api dtStartYTKRequestCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
//        NSLog(@"红外%@",[request responseJSONObject]);
//
//    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
//
//    }];


//    NSString *string = @"asdfasfdj";
//    NSLog(@"%@",string.subString(1,2));
    
//    [self startRequest];
    return YES;
}

-(void)startRequest{
    
    NSString *strURL =[[NSString alloc]initWithFormat:@"https://api.yaokongyun.cn/chip/m.php?c=r&m=none&f=13715881550&appid=15143453521708"];
    
    strURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURL *url = [NSURL URLWithString:strURL];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    
    //添加header
    NSMutableURLRequest *mutableRequest = [request mutableCopy];    //拷贝request
    [mutableRequest addValue:@"1514517504_92ece" forHTTPHeaderField:@"client"];
    request = [mutableRequest copy];        //拷贝回去
    /**********************************************/
    
    NSLog(@"%@", request.allHTTPHeaderFields);  //打印出header验证
//    NSURLConnection *connection = [[NSURLConnection alloc]
//                                   initWithRequest:request
//                                   delegate:self];
    
    NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        //（一直在等待服务器返回数据，这行代码会卡住，如果服务器没有返回数据，那么在主线程UI会卡住不能继续执行操作）
    NSLog(@"红外--%@--",data);
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
